package com.fs.controller;

import com.fs.service.MonitorCatFailSqlService;
import com.fs.service.MonitorCatLongSqlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * Created by fengshuai on 17/5/19.
 */
@Controller
@RequestMapping("/cat")
public class MonitorCatController {

    @Autowired
    private MonitorCatLongSqlService monitorCatLongSqlService;
    @Autowired
    private MonitorCatFailSqlService monitorCatFailSqlService;

    @RequestMapping("/long/info")
    @ResponseBody
    public ModelMap longSql(@RequestParam(value = "day", defaultValue = "0") int day,
                         HttpServletResponse response) {
        ModelMap map = new ModelMap();
        response.addHeader("Access-Control-Allow-Origin", "*");
        map.addAttribute("success", true).addAttribute("data", this.monitorCatLongSqlService.batchGetByDay(day));
        return map;
    }

    @RequestMapping("/fail/info")
    @ResponseBody
    public ModelMap failSql(@RequestParam(value = "day", defaultValue = "0") int day,
                         HttpServletResponse response) {
        ModelMap map = new ModelMap();
        response.addHeader("Access-Control-Allow-Origin", "*");
        map.addAttribute("success", true).addAttribute("data", this.monitorCatFailSqlService.batchGetByDay(day));
        return map;
    }
}
